package com.jml.forkjoin;

import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.RecursiveAction;


public class ForkJoinSms extends RecursiveAction {
    //    private List<String> phones;
    private int start;
    private int end;
    private int max = 10000;

    public ForkJoinSms(int start, int end) {
        this.start = start;
        this.end = end;
    }

    @Override
    protected void compute() {
        // 一次性查询数据库库10万
        if (end - start < max) {
            // sql语句查询 start ，end
//            System.out.println(phones.subList(start,end));
            System.out.println(Thread.currentThread().getName() + ",start:" + start + ",end" + end);
        } else {
            int l = (start + end) / 2;
            ForkJoinSms left = new ForkJoinSms(start, l);
            left.fork();
            ForkJoinSms right = new ForkJoinSms(l + 1, end);
            right.fork();
        }
    }

    public static void main(String[] args) {
        ForkJoinSms forkJoinSms = new ForkJoinSms(1, 100000);
        ForkJoinPool forkJoinPool = new ForkJoinPool();
        forkJoinPool.invoke(forkJoinSms);

//        try {
//            Thread.sleep(100000);
//        } catch (Exception e) {
//
//        }
    }
}
